﻿using MediatR;
using Traceability.Commont.Domains.AnimalsDomainFiles;
using Traceability.Commont.DTOs.BatchManagementDTOs;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;

namespace U.Enterprise.Api.Applications.BatchManagements
{
    public class SlaugSelectChooseHander : IRequestHandler<SlaugSelectChooseCommand, Resqults<SlaugChooseDTO>>
    {
        private readonly IBateRepository<Approach> appre;
        private readonly IBateRepository<LiveAnimalweighing> LiveAnimalweighing;
        private readonly IBateRepository<SlaughterCircle> slaughterCircle;

        public SlaugSelectChooseHander(IBateRepository<Approach> appre, IBateRepository<LiveAnimalweighing> liveAnimalweighing, IBateRepository<SlaughterCircle> slaughterCircle)
        {
            this.appre = appre;
            LiveAnimalweighing = liveAnimalweighing;
            this.slaughterCircle = slaughterCircle;
        }

        public async Task<Resqults<SlaugChooseDTO>> Handle(SlaugSelectChooseCommand request, CancellationToken cancellationToken)
        {
            try
            {
                Resqults<SlaugChooseDTO> res = new Resqults<SlaugChooseDTO>();
                var list = from a in appre.GetAll()
                           join b in LiveAnimalweighing.GetAll() on a.ApproachId equals b.ApproachId
                           join c in slaughterCircle.GetAll() on b.SlaughterCircleId equals c.SlaughterCircledId
                           select new SlaugChooseDTO()
                           {
                               LiveAnimalweighingId = b.LiveAnimalweighingId,
                               ApproachNo = a.ApproachNo,
                               ApproachBatch = a.ApproachBatch,
                               SlaugBatch = a.ApproachBatch,
                               Suppers = a.Suppliers,
                               SendType = "",
                               SlaugType = "",
                               ShopId = 1,
                               SlaugNum = 0,
                               SlaugTime = DateTime.Now,
                               SlaugDate = "now",
                               SlaughterCircle = c.SlaughterCircleName,
                               Times = 3,
                               Raemk="",
                           };

                res.Date=list.ToList();
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
